﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace BugzX.Repositories
{
    public static class UserRepository
    {
        public static bool ValidateUser(string username, string password)
        {
            var context = new BugzXDBEntities();

            var user = from u in context.Users
                       where u.UserName.ToLower().Trim() == username.ToLower().Trim()
                           && u.Password == password
                        select u;

            return user.Count() > 0;
        }

        public static int GetCurrentUserId()
        {
            var context = new BugzXDBEntities();

            string username = HttpContext.Current.User.Identity.Name;

            var user = from u in context.Users
                       where u.UserName.ToLower().Trim() == username.ToLower().Trim()
                       select u;

            return user.FirstOrDefault().UserId;
        }

        public static string GetUserName(int userId)
        {
            var context = new BugzXDBEntities();

            var user = from u in context.Users
                       where u.UserId == userId
                       select u;

            return user.FirstOrDefault().UserName;
        }
    }
}